package com.iseastar.guojiang.util;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;

/**
 * Created by joker on 2017/7/26.
 */

public class BluetoothUtils {
    private static BluetoothAdapter bluetoothAdapter = BluetoothAdapter
            .getDefaultAdapter();

    /**
     * 打开蓝牙
     */
    public static void openBluetooth(Activity activity) {
        Intent enableBtIntent = new Intent(
                BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(enableBtIntent, 1);

    }

    /**
     * 关闭蓝牙
     */
    public static void closeBluetooth() {
        bluetoothAdapter.disable();
    }

    /**
     * 判断蓝牙是否打开
     *
     * @return boolean
     */
    public static boolean isOpen() {
        return bluetoothAdapter.isEnabled();
    }

    public static void serachDevice() {
        // 寻找蓝牙设备，android会将查找到的设备以广播形式发出去
        bluetoothAdapter.startDiscovery();
    }
}
